{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f5fc7e0d",
   "metadata": {},
   "source": [
    "# CNN\n",
    "\n",
    "tf=2.9.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f4b0db1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2.9.1'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "\n",
    "tf.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "516c6b96",
   "metadata": {},
   "source": [
    "## Conv1D\n",
    "\n",
    "```python\n",
    "tf.keras.layers.Conv1D(\n",
    "    filters,\n",
    "    kernel_size,\n",
    "    strides=1,\n",
    "    padding='valid',\n",
    "    data_format='channels_last',\n",
    "    dilation_rate=1,\n",
    "    groups=1,\n",
    "    activation=None,\n",
    "    use_bias=True,\n",
    "    kernel_initializer='glorot_uniform',\n",
    "    bias_initializer='zeros',\n",
    "    kernel_regularizer=None,\n",
    "    bias_regularizer=None,\n",
    "    activity_regularizer=None,\n",
    "    kernel_constraint=None,\n",
    "    bias_constraint=None,\n",
    "    **kwargs\n",
    ")\n",
    "``` \n",
    "- filters: Integer # 输出特征层数\n",
    "- kernel_size      # 卷积核大小，第一个整数\n",
    "- strides=1        # 步幅度\n",
    "- padding='valid'  # 填充模式 \n",
    "\n",
    "\n",
    "- input shape: [batch, steps, dim]\n",
    "- output shape: [batch, new_steps, filters]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3a3392d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4, 8, 32)\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "input_shape = (4, 10, 128)  # [batch, steps, dim]\n",
    "x = tf.random.normal(input_shape)\n",
    "y = tf.keras.layers.Conv1D(filters=32, \n",
    "                           kernel_size=3, \n",
    "                           activation='relu',\n",
    "                           input_shape=input_shape[1:])(x)\n",
    "print(y.shape) # [batch, new_steps, filters] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "945098a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4, 7, 8, 32)\n"
     ]
    }
   ],
   "source": [
    "# 处理后面2个维度\n",
    "\n",
    "input_shape = (4, 7, 10, 128)\n",
    "x = tf.random.normal(input_shape)\n",
    "y = tf.keras.layers.Conv1D(filters=32, \n",
    "                           kernel_size=3, \n",
    "                           activation='relu', \n",
    "                           input_shape=input_shape[2:])(x)\n",
    "print(y.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb625784",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae0e5145",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "92d0ec0f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cb9a7ed",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e15b09d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09d34579",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ba2848a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "368bba55",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "141102ac",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46991693",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d38b061f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77a83741",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b282e6d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2c0cad1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ba0c891",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
